<template>
 <el-dialog
      class="closeMainWinDialog"
      :visible.sync="closeMainWinDialogVisible"
       title="关闭提示"
       width="30%" 
      :append-to-body='true'
      >
        <img src="@/page/main/assets/mark64.png" alt="" style="float:left;margin-right:30px;">
      <div>
        <p>你点击了关闭按钮，你是想：</p>
         <el-radio-group v-model="closeWinSelect">
          <el-radio :label="0" style="margin-bottom:10px">最小化到托盘，不退出程序</el-radio><br>
          <el-radio :label="1">关闭</el-radio>
        </el-radio-group>
        <!-- <el-radio v-model="closeWinSelect" label="0">备选项</el-radio><br>
        <el-radio v-model="closeWinSelect" label="1">备选项</el-radio> -->
      </div>
      <el-checkbox v-model="closeWinSelectChecked">不再提示</el-checkbox>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeMainWinDialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="confirmCloseWinDialog">确 定</el-button>
      </div>
    </el-dialog>
</template>
<script>
import { ipcRenderer } from 'electron'
export default {
  data() {
    return {
      closeMainWinDialogVisible: false,
      closeWinSelect: 0
    }
  },
  mounted() {
    this.getCommandColse()
  },
  methods: {
    getCommandColse() {
      ipcRenderer.on('closeMainWin', () => {
        this.closeMainWinDialogVisible = true
      })
    },
    confirmCloseWinDialog() {
      this.closeMainWinDialogVisible = false
      if (this.closeWinSelect === 0) {
        setTimeout(function() {
          // 500毫秒后实现的方法写在这个方法里面，延迟执行，否则点击托盘时会出现闪烁显示一下这个对话框，体验不好,
          // element-ui 的Dialog被蒙板遮住原因及解决办法 https://blog.csdn.net/solocoder/article/details/80936549
          ipcRenderer.send('minimizeCloseWin')
        }, 1 * 300)// 延迟300毫秒
      } else {
        ipcRenderer.send('closeMainWin')
      }
    }
  }
}
</script>